package myJs.download

import myJs.cps.BootstrapTableCp.Column
import myJs.tool.Pojo.{NumericSearch, TextSearch}
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import typings.csstype.csstypeStrings

import scala.collection.immutable.SeqMap

//import myJs.MainCp
import myJs.api.Api
//import myJs.cps.BootstrapTableCp.Column
import myJs.cps._
//import myJs.myPkg.ReactRouterDOM
//import myJs.myPkg.bootstrap.jquery.ScrollspyOptions
//import myJs.myPkg.jquery.$
//import myJs.tool.Pojo.{NumericSearch, TextSearch}
//import org.scalajs.dom.document
//import slinky.core.annotations.react
//import slinky.core.facade.Hooks._
//import slinky.core.{FunctionalComponent, TagElement}
//import slinky.web.SyntheticMouseEvent
import slinky.web.html._
//import typings.csstype.csstypeStrings
//import upickle.default.{reader, writeJs}
//
//import scala.collection.immutable.SeqMap
////import myJs.myPkg.i18n.ReactI18next
import myJs.Implicits._

/**
 * Created by yz on 21/1/2022
 */
@react object HCCp {

  type Props = Unit

  val component = FunctionalComponent[Props] { props =>

    object FTool {

      def tbFmt(field: String) = (v: ujson.Value, row: ujson.Obj) => {
        field match {
          case "expressionProfile" =>
            val url = s"${Api.apiUrl}/gepLiver/tool/downloadFile"
            a(href := s"${url}?fileName=Download/Human Cell Line/${v.myStr}", v.myStr)()
          case _ => span(v.myStr)()
        }
      }

      def comVFmt(fileTitle: String) = (v: ujson.Value, row: ujson.Obj) => {
        fileTitle match {
          case "Freq" =>
            (v.str.toDouble * 100).toFixed(1)
          case _ => v.myStr

        }

      }
    }

    val map = SeqMap(
      "dataset" -> "Dataset",
      "phenotype" -> "Phenotype",
      "expressionProfile" -> "Expression Profile",
    )
    val columns = map.map { case (k, v) =>
      val searchKind = v match {
        case "Freq" => NumericSearch
        case _ => TextSearch
      }
      val title = v
      val fmt = FTool.tbFmt(k)
      val comVF = FTool.comVFmt(v)
      Column(field = k, title = title, operable = false, searchKind = searchKind, formatter = fmt, comVF = comVF)
    }.toList

    val datas = List(
      ujson.Obj(
        "dataset" -> "GepLiver-CL",
        "phenotype" -> "HCC; ICC",
        "expressionProfile" -> "CL_expr.txt",
      ),
    )

    BootstrapTableCp(columns = columns, datas = datas, pagination = false,
      thStyle = Style(justifyContent = csstypeStrings.center), tdStyle = Style(textAlign = csstypeStrings.center))

  }

}
